const state = {
  // 记录每个页面的状态
  pageStates: {
    // electric: { 
    //   showForm: false, 
    //   formType: '', // 'add', 'edit', 'view'等
    //   formId: null
    // }
  }
}

const mutations = {
  // 设置页面状态
  SET_PAGE_STATE: (state, { page, data }) => {
    state.pageStates[page] = data
  },
  // 移除页面状态
  REMOVE_PAGE_STATE: (state, page) => {
    delete state.pageStates[page]
  }
}

const actions = {
  // 保存页面状态
  setPageState({ commit }, { page, data }) {
    commit('SET_PAGE_STATE', { page, data })
  },
  // 移除页面状态
  removePageState({ commit }, page) {
    commit('REMOVE_PAGE_STATE', page)
  }
}

const getters = {
  // 获取特定页面状态
  getPageState: state => page => {
    return state.pageStates[page] || null
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
} 